﻿
using Microsoft.Extensions.Configuration;
using Panuon.UI.Silver.Core;
using ProjectModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace ViewModel
{
    public class MainViewModel : PropertyChangedBase
    {
        public ObservableCollection<TreeViewItemModel> MenuItems { get; set; } = new ObservableCollection<TreeViewItemModel>();

        public static IConfigurationRoot root = null;
        public static string BaseUrl = string.Empty;

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(Dictionary<string, string> dicConfig)
        {
            //root = Common.ConfigHelp.GetConfigurationRoot(dicConfig["urlCofing"]);
            //GetData();
            MenuItems = new ObservableCollection<TreeViewItemModel>()
            {
                new TreeViewItemModel("系统管理","系统管理", "\uf05a")
                {
                     MenuItems = new ObservableCollection<TreeViewItemModel>()
                     {
                         new TreeViewItemModel("用户管理","用户管理", "","ViewPage/SystemPage/UserManage.xaml",null)
                     }
                },
                new TreeViewItemModel("权限","权限管理", "\uf0eb")
                {
                     MenuItems = new ObservableCollection<TreeViewItemModel>()
                     {
                         new TreeViewItemModel("用户管理","用户管理", "","ViewPage/SystemPage/UserManage.xaml",null)
                     }
                }
            };
        }

        //public async void GetData()
        //{
        //    BaseUrl = root.GetSection("HostUrl:BaseUrl").Value;
        //    var GetMenu = root.GetSection("MenuApi:GetMenu").Value;
        //   // var result = await Common.HttpHelper.HttpGetAsync<ProjectModel.ResultModel>(BaseUrl + GetMenu);

        //    var DataList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<MenuModel>>(result.data.ToString());
        //    //var DataList = (List<MenuModel>)result.data;
        //    foreach (var item in DataList.Where(a => string.IsNullOrWhiteSpace(a.StrUrl)))
        //    {
        //        var mode = new TreeViewItemModel(item.Header, item.Tag, item.Icon);
        //        foreach (var itemItem in item.ChildItme)
        //        {
        //            mode.MenuItems.Add(new TreeViewItemModel(itemItem.Header, itemItem.Tag, itemItem.Icon, itemItem.StrUrl));
        //        }
        //        MenuItems.Add(mode);
        //    }


        //}


    }
}
